import { Button } from "antd";
import React from "react";
import { connect } from "./../../source/react-redux/index";
import actions from "./../../store/actions/index.js";
class Age extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {};
  }
  componentDidMount() {
    console.log("age", this.props);
  }
  changeName = () => {
    let { dispatch } = this.props;
    //   console.log('actions:',actions)
    dispatch(actions.setName("李四"));
  };
  render() {
    const { age, dispatch } = this.props;
    return (
      <div>
        年龄: <span>{age}</span>{" "}
        <Button onClick={this.changeName} type="primary">
          改变姓名
        </Button>
        <Button
          style={{ marginLeft: "20px" }}
          onClick={() => dispatch(actions.asyncSetName("阿德托昆博弟弟"))}
          type="primary"
        >
          异步改变姓名
        </Button>
        <Button
          style={{ marginLeft: "20px" }}
          onClick={() =>
            dispatch(actions.promiseSetName(dispatch, "史蒂芬库里"))
          }
          type="primary"
        >
          promise改变姓名
        </Button>
      </div>
    );
  }
}
const mapStateToProps = (state) => {
  return {
    age: state.age.age,
  };
};
const mapDispatchToProps = (dispatch) => {
  return {
    dispatch,
  };
};
export default connect(mapStateToProps, mapDispatchToProps)(Age);
